package com.ruoyi.web.controller.mdm;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.mdm.domain.SearchConditionInfo;
import com.ruoyi.mdm.service.IMdmApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.servlet.http.HttpServletRequest;

/**
 * 提供给其他系统查询SKU的接口
 *
 * @author shiseido
 * @date 2025-03-01
 */
@RestController
@RequestMapping("/mdm/v1/api")
public class MdmApiController extends BaseController {

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private IMdmApiService mdmApiService;

    /**
     * SKU查询接口
     */
    @GetMapping("/getSkuInfo")
    public Object getSkuInfo(SearchConditionInfo searchConditionInfo) {

        // ES模糊检索
        searchConditionInfo.setSearchType("es");

//        // 销售渠道不为空时 转换为list对象
//        if (StringUtils.isNotEmpty(searchConditionInfo.getSalesChannelCode())) {
//            List<String> salesChannelCodeList = Arrays.asList(searchConditionInfo.getSalesChannelCode().split(","));
//            searchConditionInfo.setSalesChannelCodeList(salesChannelCodeList);
//        }

        // pageNum pageSize 没有传输的情况下  默认最大值
        if (searchConditionInfo.getPageNum() == 0 || searchConditionInfo.getPageSize() == 0) {
            searchConditionInfo.setPageNum(1);
            searchConditionInfo.setPageSize(10000);
        }

        // 检索条件
        return mdmApiService.selectSkuInfoData(request, searchConditionInfo);
    }

}
